﻿@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['form', 'step', 'common', 'dtree', 'optimizeSelectOption'], function () {
        var $ = layui.$,
            form = layui.form,
            dtree = layui.dtree,
            common = layui.common,
            step = layui.step;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('stepForm');
        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '85%', //设置容器宽度
            stepWidth: '300px',
            height: '450px',
            stepItems: [{
                title: '填写角色信息'
            }, {
                title: '设置功能权限'
            }, {
                title: '设置字段权限'
            }]
        });
        $(function () {
            initControl();
            if (!!keyValue) {
                common.ajax({
                    url: "/SystemOrganize/Role/GetFormJson",
                    dataType: "json",
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('stepForm', data);
                        common.setReadOnly('stepForm');
                    }
                });
            }
            form.render();
        });
        wcLoading.close();
        // 初始化树
        var DemoTree1 = dtree.render({
            elem: "#demoTree1",
            width: '200px',
            method: "GET",
            async: false,
            checkbar: true,
            line: true,  // 显示树线
            initLevel: 0,
            icon: "-1", // 隐藏二级图标
            checkbarType: "p-casc",
            scroll: "#toolbarDiv1", // 绑定div元素
            url: "/SystemOrganize/RoleAuthorize/GetPermissionTree?v=" + new Date().Format("yyyy-MM-dd hh:mm:ss"), // 使用url加载（可与data加载同时存在）
            request: { roleId: keyValue }
        });
        function initControl() {
            $("#F_OrganizeId").bindSelect({
                url: "/SystemOrganize/SystemSet/GetListJson",
                id: "F_Id",
                text: "F_CompanyName"
            });
            $("#F_Type").bindSelect({
                data: top.clients.dataItems['RoleType'],
                id: "",
            });
        }
        var role;
        form.on('submit(formStep)', function (data) {
            role = data.field
            step.next('#stepForm');
            return false;
        });
        var moduleids = [];
        form.on('submit(formStep2)', function (data) {
            var params = dtree.getCheckbarNodesParam("demoTree1");
            for (var i = 0; i < params.length; i++) {
                moduleids.push(params[i].nodeId);
            }
            // 初始化树
            var DemoTree2 = dtree.render({
                elem: "#demoTree2",
                width: '200px',
                method: "POST",
                async: false,
                checkbar: true,
                line: true,  // 显示树线
                initLevel: 0,
                icon: "-1", // 隐藏二级图标
                checkbarType: "p-casc",
                scroll: "#toolbarDiv2", // 绑定div元素
                url: "/SystemOrganize/RoleAuthorize/GetPermissionFieldsTree?v=" + new Date().Format("yyyy-MM-dd hh:mm:ss"), // 使用url加载（可与data加载同时存在）
                request: { roleId: keyValue, moduleids: String(moduleids) }
            });
            step.next('#stepForm');
            return false;
        });
        form.on('submit(formStep3)', function (data) {
            var postData = role;
            var params = dtree.getCheckbarNodesParam("demoTree2");
            var note = [];
            for (var i = 0; i < params.length; i++) {
                note.push(params[i].nodeId);
            }
            postData["permissionbuttonIds"] = String(moduleids);
            postData["permissionfieldsIds"] = String(note);
            common.submitForm({
                url: "/SystemOrganize/Role/SubmitForm?keyValue=" + keyValue,
                param: postData,
                success: function () {
                    common.parentreload("data-search-btn");
                }
            })
            return false;
        });
        $('.pre').click(function () {
            step.pre('#stepForm');
        });
    })
</script>
<div class="layuimini-container">
    <div class="layuimini-main">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm">
                        <div carousel-item>
                            <div>
                                <form class="layui-form">
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">归属公司</label>
                                        <div class="layui-input-block">
                                            <select id="F_OrganizeId" name="F_OrganizeId" lay-verify="required">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">角色名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="F_FullName" name="F_FullName" lay-verify="required" class="layui-input" placeholder="请填写角色名称">
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">角色编号</label>
                                        <div class="layui-input-block">
                                            <input id="F_EnCode" name="F_EnCode" type="text" lay-verify="required" class="layui-input" placeholder="请输入角色编号" />
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">角色类型</label>
                                        <div class="layui-input-block">
                                            <select id="F_Type" name="F_Type" lay-verify="required">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">显示顺序</label>
                                        <div class="layui-input-block">
                                            <input id="F_SortCode" name="F_SortCode" type="number" pattern="[0-9]*" class="layui-input" lay-verify="required" />
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-hide">
                                        <label class="layui-form-label">选项</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="F_EnabledMark" id="F_EnabledMark" checked="" value="true" title="有效标识">
                                        </div>
                                    </div>
                                    <div class="layui-form-item layui-form-text layui-hide">
                                        <label class="layui-form-label">备注</label>
                                        <div class="layui-input-block">
                                            <textarea id="F_Description" name="F_Description" class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group-bottom text-right">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form layuimini-form">
                                    <div class="layui-form-item ">
                                        <div style="height: 350px;overflow: auto;" id="toolbarDiv1">
                                            <ul id="demoTree1" class="dtree" data-id="0"></ul>
                                        </div>
                                    </div>
                                    <div class="form-group-bottom text-right">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form layuimini-form">
                                    <div class="layui-form-item ">
                                        <div style="height: 350px;overflow: auto;" id="toolbarDiv2">
                                            <ul id="demoTree2" class="dtree" data-id="0"></ul>
                                        </div>
                                    </div>
                                    <div class="form-group-bottom text-right">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

    </div>
</div>
